########################################################
# CMake file for CPAR Runtime
########################################################

CMAKE_MINIMUM_REQUIRED( VERSION 2.6 )

AUX_SOURCE_DIRECTORY( src RT_COMMON_SRC )
AUX_SOURCE_DIRECTORY( src/win64 RT_WIN64_SRC )
AUX_SOURCE_DIRECTORY( src/macos RT_MACOS_SRC )
AUX_SOURCE_DIRECTORY( src/linux RT_LINUX_SRC )

FILE( GLOB RT_COMMON_INCLUDES "include/*.h" )
FILE( GLOB RT_WIN64_INCLUDES "include/win64/*.h" )
FILE( GLOB RT_MACOS_INCLUDES "include/macos/*.h" )
FILE( GLOB RT_LINUX_INCLUDES "include/linux/*.h" )

LIST( APPEND RT_COMMON_SRC ${RT_COMMON_INCLUDES} )
LIST( APPEND RT_WIN64_SRC ${RT_WIN64_INCLUDES} )
LIST( APPEND RT_MACOS_SRC ${RT_MACOS_INCLUDES} )
LIST( APPEND RT_LINUX_SRC ${RT_LINUX_INCLUDES} )

# Global includes
INCLUDE_DIRECTORIES( include )

# Project file grouping
SOURCE_GROUP( sources REGULAR_EXPRESSION .+\\.c )
SOURCE_GROUP( includes REGULAR_EXPRESSION .+\\.h )
SOURCE_GROUP( defs REGULAR_EXPRESSION .+\\.def )

IF( UNIX )
	ADD_DEFINITIONS( " -ansi -pedantic --std=c99 -Wno-variadic-macros " )

	IF(CPAR_OS_LINUX)
		INCLUDE_DIRECTORIES( include/linux )
		LIST( APPEND RT_COMMON_SRC ${RT_LINUX_SRC} )
	ENDIF ( CPAR_OS_LINUX )
	
	IF( APPLE )
		INCLUDE_DIRECTORIES( include/macos )
		LIST( APPEND RT_COMMON_SRC ${RT_MACOS_SRC} )
	ENDIF ( APPLE )
ELSE ( UNIX )
	ADD_DEFINITIONS( "/W3 -D_CRT_SECURE_NO_DEPRECATE /WX" )
	
	#SET_TARGET_PROPERTIES ( core PROPERTIES COMPILE_FLAGS "/analyze /WX /wd4047" )
	
	LIST ( APPEND RT_COMMON_SRC ${RT_WIN64_SRC} )
	INCLUDE_DIRECTORIES( include/win64 )

ENDIF( UNIX )

ADD_LIBRARY ( rt STATIC ${RT_COMMON_SRC} )

# Testing
ADD_EXECUTABLE ( RT-FORALL-EXEM-CPAR src/tests/forall-exem.cpar.c )
TARGET_LINK_LIBRARIES (RT-FORALL-EXEM-CPAR rt)

ADD_EXECUTABLE ( RT-COBEGIN-EXEM-CPAR src/tests/cobegin-exem.cpar.c )
TARGET_LINK_LIBRARIES (RT-COBEGIN-EXEM-CPAR rt)

ADD_EXECUTABLE ( RT-MONITOR-EXEM-CPAR src/tests/monitor-exem.cpar.c )
TARGET_LINK_LIBRARIES (RT-MONITOR-EXEM-CPAR rt)

ADD_EXECUTABLE ( RT-PARBEGIN-EXEM-CPAR src/tests/parbegin-exem.cpar.c )
TARGET_LINK_LIBRARIES (RT-PARBEGIN-EXEM-CPAR rt)

ADD_EXECUTABLE ( RT-EVENT-EXEM-CPAR src/tests/event-exem.cpar.c )
TARGET_LINK_LIBRARIES (RT-EVENT-EXEM-CPAR rt)

ADD_TEST(NAME RT-FORALL COMMAND RT-FORALL-EXEM-CPAR)
ADD_TEST(NAME RT-COBEGIN COMMAND RT-COBEGIN-EXEM-CPAR)
ADD_TEST(NAME RT-MONITOR COMMAND RT-MONITOR-EXEM-CPAR)
ADD_TEST(NAME RT-PARBEGIN COMMAND RT-PARBEGIN-EXEM-CPAR)
ADD_TEST(NAME RT-EVENT COMMAND RT-EVENT-EXEM-CPAR)

